﻿/*
--------------------------------------
File: Serializer.cs
Project: Themaopdracht 7
Author: Roel Blaauwgeers

Description:
Used to store and read the image data.
--------------------------------------
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace THO7_Team8
{
    public class Serializer
    {
        public static void serialize(Object o , String filename)
        {
            FileStream flStream = new FileStream(filename,
            FileMode.OpenOrCreate, FileAccess.Write);
            try
            {
                BinaryFormatter binFormatter = new BinaryFormatter();
                binFormatter.Serialize(flStream, o);
            }
            finally
            {
                flStream.Close();
               
            }
        }

        public static Object deSerialize(String filename)
        {
            Object deSerializer = new Object();

            FileStream flStream = new FileStream(filename,
                FileMode.Open, FileAccess.Read);
            try
            {
                BinaryFormatter binFormatter = new BinaryFormatter();
                deSerializer = binFormatter.Deserialize(flStream);
            }
            finally
            {
                flStream.Close();

            }
            return deSerializer;
        }
    }
}
